package com.iweb.config;

import com.iweb.listener.SysNoticeListener;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class RabbitConfig {

    @Autowired
    private SysNoticeListener sysNoticeListener;

    /**
     * 系统通知消费容器
     *
     * @param connectionFactory
     * @return
     */
    @Bean("sysNoticeContainer")
    public SimpleMessageListenerContainer sysNoticeContainer(ConnectionFactory connectionFactory) {
        SimpleMessageListenerContainer listenerContainer =
                new SimpleMessageListenerContainer(connectionFactory);
        listenerContainer.setExposeListenerChannel(true);// 使用 channel 进行通信
        //设置自己编写的监听器
        listenerContainer.setMessageListener(sysNoticeListener);
        return listenerContainer;
    }
}
